package com.mg.admin.service.weixin.handler;

import java.util.Map;

import com.mg.admin.bean.admin.WxFansVO;
import com.mg.admin.service.admin.WxFansService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;

/**
 * 
 * @author Binary Wang
 *
 */
@Component
public class UnsubscribeHandler extends AbstractHandler {

    @Autowired
    private WxFansService wxFansService;

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
            Map<String, Object> context, WxMpService wxMpService,
            WxSessionManager sessionManager) {
        String openId = wxMessage.getFromUser();
        this.logger.info("取消关注用户 OPENID: " + openId);
        WxFansVO wxFansVO = new WxFansVO();
        wxFansVO.setOpenid(openId);
        wxFansService.saveSubscribeUser(wxFansVO);
        return null;
    }

}
